#include "../src/CameraControlProxy.hpp"
#include "../src/NetworkForwardProxy.hpp"
#include "../src/ServerUIProxy.hpp"
#include "../src/WorkDataProxy.hpp"
#include "../src/ConfigReader.hpp"
#include "../src/ReviewUIProxy.hpp"

#include <iostream>
#include <unistd.h>

CameraControlProxy cameracontrol;
NetworkForwardProxy networkforward;
ServerUIProxy ui;
WorkDataProxy workdata;
ConfigReader config;
ReviewUIProxy reviewUI;

long currentRecordID;

int main()
{
  networkforward.funcCreateTask=[](std::string str){
    return workdata.CreateTask(str);
  };
  networkforward.funcStartRecord=[](long taskid,long stuid){
    currentRecordID=workdata.CreateRecord(taskid,stuid);
    cameracontrol.StartRecord(workdata.GetRecordPath(currentRecordID));
    ui.SetRecordStatus(true);
  };
  networkforward.funcStopRecord=[](){
    cameracontrol.StopRecord();
    workdata.FinishRecord(currentRecordID);
    ui.SetRecordStatus(false);
  };
  networkforward.funcGetNetworkPort=[](){
    return 10090;
  };
  networkforward.funcGetStudentInfo=[](long id){
    return workdata.GetStudentInfo(id);
  };
  networkforward.funcMobileConnectChange=[](bool status){
    ui.SetMobileConnectStatus(status);
  };
  networkforward.funcGetRecordStatus=[](){
    return cameracontrol.RecordStatus();
  };

  reviewUI.funcGetAllTaskList=[](){
    workdata.LoadTaskInf();
    return workdata.GetTaskIDList();
  };
  reviewUI.funcGetHandleFinishRecordList=[](){
    return workdata.GetRecordHandleFinishList();
  };
  
  reviewUI.funcGetTaskInf=[](long id){
    return workdata.GetTaskInf(id);
  };

  reviewUI.funcGetRecordInf=[](long rec_id){
    auto recordInf=workdata.GetRecordInf(rec_id);
    auto record_path=workdata.GetRecordPath(rec_id);
    return std::make_tuple(
      std::get<0>(recordInf),
      std::get<2>(recordInf),
      record_path
    );
  };
  reviewUI.funcGetRecordList=[](long task_id){
    return workdata.GetRecordHandleFinishList();
  };
  reviewUI.funcGetCameraIDList=[](){
    return config.GetCameraID();
  };
  reviewUI.funcGetHandleFinishRecordListWithTask=[](long task){
    return workdata.GetRecordHandleFinishListWithTask(task);
  };
  reviewUI.funcOutputData=[](long id,std::string path){
    return workdata.OutputData(id, path);
  };

  networkforward.Boot();
  reviewUI.Boot();
  ui.Boot();
  

  while(sleep(10)==0)
    ;
}
